package zhang.test.netfits_youmeng;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;

import com.umeng.analytics.MobclickAgent;

import java.util.HashMap;

import butterknife.ButterKnife;
import butterknife.OnClick;



/**
 * Created by Administrator on 2016/12/12.
 */

public class ResultZActivity extends AppCompatActivity {

    private static final String TAG = "ResultZActivity" ;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result);
        ButterKnife.bind(this);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);//这句话必须要写
    }

    @OnClick({R.id.bt_fa, R.id.bt_su, R.id.bt_ca})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_fa: // 失败
                try {
                    int i = Integer.parseInt(null);
                    int a = i / 5;
                }catch(Exception e) {
                    Log.d(TAG, "error: " +  e.getMessage());
                    Log.d(TAG, "error: " +  e.getCause());
                    Log.d(TAG, "error: " +  e.toString());
                    Log.d(TAG, "error: " +  e.getLocalizedMessage());
                    MobclickAgent.reportError(this, e.toString());
                    MobclickAgent.reportError(this, "用户支付失败");

                    MobclickAgent.onEvent(this, "user");
                    Log.d(TAG, "MobclickAgent===============");
                }
                HashMap<String, String> map1 = new HashMap<String, String>();
                map1.put("mode", "fail");
                MobclickAgent.onEvent(ResultZActivity.this, "payResult", map1);
                startActivity(new Intent(this, HomeActivity.class));
                break;

            case R.id.bt_su: // 成功
                HashMap<String, String> map2 = new HashMap<String, String>();
                map2.put("mode", "success");
                MobclickAgent.onEvent(ResultZActivity.this, "payResult", map2);
                startActivity(new Intent(this, HomeActivity.class));
                break;

            case R.id.bt_ca: // 取消
                try {
                    int i = Integer.parseInt(null);
                    int a = i / 5;
                }catch(Exception e) {
                    MobclickAgent.reportError(this, e.toString());
                    MobclickAgent.reportError(this, "用户支付取消");
                }

                HashMap<String, String> map3 = new HashMap<String, String>();
                map3.put("mode", "cancle");
                MobclickAgent.onEvent(ResultZActivity.this, "payResult", map3);
                startActivity(new Intent(this, HomeActivity.class));
                break;
        }
    }

    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.bind(this).unbind();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            MobclickAgent.onEvent(ResultZActivity.this, "back");
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
